﻿using CleanArchitecture.Infrastructure.Entities.SystemModules;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CleanArchitecture.Infrastructure.DataMapping.SystemModules
{
    /// <summary>
    /// Represents a permission record-customer role mapping configuration
    /// </summary>
    public partial class AdminRoleSystemModuleMappingMap : NowaEntityTypeConfiguration<AdminRoleSystemModuleMapping>
    {
        #region Methods

        /// <summary>
        /// Configures the entity
        /// </summary>
        /// <param name="builder">The builder to be used to configure the entity</param>
        public override void Configure(EntityTypeBuilder<AdminRoleSystemModuleMapping> builder)
        {
            builder.ToTable("adminrole_systemmodule_mapping");
            builder.HasKey(mapping => new { mapping.FKAdminRoleId, mapping.FKSystemModuleId });

            builder.Property(mapping => mapping.FKAdminRoleId).HasColumnName("FK_AdminRole_Id");
            builder.Property(mapping => mapping.FKSystemModuleId).HasColumnName("FK_SystemModule_Id");
            builder.Property(mapping => mapping.IsAllow).IsRequired();
            builder.Property(mapping => mapping.AuthorizedButtonIds).HasMaxLength(500);
            builder.HasOne(mapping => mapping.AdminRole)
                .WithMany(role => role.AdminroleSystemModuleMappings)
                .HasForeignKey(mapping => mapping.FKAdminRoleId)
                .IsRequired();

            builder.HasOne(mapping => mapping.SystemModule)
                .WithMany(record => record.AdminroleSystemModuleMappings)
                .HasForeignKey(mapping => mapping.FKSystemModuleId)
                .IsRequired();

            builder.Ignore(mapping => mapping.Id);

            base.Configure(builder);
        }

        #endregion
    }
}
